package com.registration.satoken;

import cn.dev33.satoken.stp.StpInterface;
import com.registration.bean.MenuBean;
import com.registration.bean.PCUserBean;
import com.registration.mapper.MenuMapper;
import com.registration.mapper.PCUserMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
public class StpInterfaceImpl implements StpInterface {


    @Autowired
    private MenuMapper menuMapper;

    @Autowired
    private PCUserMapper pcUserMapper;

    @Override
    public List<String> getPermissionList(Object username, String loginType) {
        PCUserBean pcUserBean = pcUserMapper.login( username.toString());


        if (pcUserBean != null) {
            Integer loginId = pcUserBean.getPc_user_id();
            List<MenuBean> menuList = menuMapper.getMenuListByPCUserId(Integer.parseInt(loginId.toString()));
            List<String> perms = new ArrayList<>();
            for (MenuBean menuBean : menuList) {
                perms.add(menuBean.getPerms());
            }
            return perms;
        }
       return null;
    }


    @Override
    public List<String> getRoleList(Object o, String s) {
        return null;
    }
}
